package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.TuningPoJo;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.SupplierCommunicateEnum;
import com.xbongbong.saas.enums.dictionary.CommunicateTypeEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/17 19:35
 * @since v1.0
 */
@Getter
public enum TempSupplierCommunicateEnum {
    // 供应商跟进
    BASE_INFO(SupplierCommunicateEnum.BASE_INFO),
    SUPPLIER_ID(SupplierCommunicateEnum.SUPPLIER_ID),
    SUPPLIER_CONTACT(SupplierCommunicateEnum.SUPPLIER_CONTACT),
    TYPE(SupplierCommunicateEnum.TYPE),
    COMMUNICATE_TIME(SupplierCommunicateEnum.COMMUNICATE_TIME),
    COMMUNICATE_BUSINESS(SupplierCommunicateEnum.COMMUNICATE_BUSINESS),
    MEMO(SupplierCommunicateEnum.MEMO),
    VIDEO(SupplierCommunicateEnum.VIDEO),
    ADDRESS(SupplierCommunicateEnum.ADDRESS),
    IMAGES(SupplierCommunicateEnum.IMAGES),
    FILE(SupplierCommunicateEnum.FILE),

    SYSTEM_INFO(SupplierCommunicateEnum.SYSTEM_INFO),
    CREATOR_ID(SupplierCommunicateEnum.CREATOR_ID),
    ADD_TIME(SupplierCommunicateEnum.ADD_TIME),
    UPDATE_TIME(SupplierCommunicateEnum.UPDATE_TIME),
    //IF_REMIND(SupplierCommunicateEnum.IF_REMIND),
    AUTO_GEN(SupplierCommunicateEnum.AUTO_GEN),
    USER_ID(SupplierCommunicateEnum.USER_ID),
    USER_NAME(SupplierCommunicateEnum.USER_NAME),
    USER_AVATAR(SupplierCommunicateEnum.USER_AVATAR),
    SUPPLIER_NAME_LINK_TEXT(SupplierCommunicateEnum.SUPPLIER_NAME_LINK_TEXT),
    SUPPLIER_CONTACT_NAME_LINK_TEXT(SupplierCommunicateEnum.SUPPLIER_CONTACT_NAME_LINK_TEXT),

    COMMUNICATE_BUSINESS_TYPE(SupplierCommunicateEnum.COMMUNICATE_BUSINESS_TYPE),
    COMMUNICATE_BUSINESS_LINK_TEXT(SupplierCommunicateEnum.COMMUNICATE_BUSINESS_LINK_TEXT),
    AT_USERNAME(SupplierCommunicateEnum.AT_USERNAME)
    ;
    private SupplierCommunicateEnum anEnum;

    TempSupplierCommunicateEnum(SupplierCommunicateEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempSupplierCommunicateEnum> getAllEnum() {
        List<TempSupplierCommunicateEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化跟进方式
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initType(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDictionaryFlag(1);
//        fieldAttrEntity.setItems(InitExplainsHelper.setCombItem(CommunicateTypeEnum.FACE_TO_FACE.getName() + "," + CommunicateTypeEnum.TELEPHONE_CALL.getName() + "," + CommunicateTypeEnum.INTERNET_VISIT.getName()));
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(CommunicateTypeEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化跟进时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initCommunicateTime(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDateType(DateTimeEnum.DATETIME.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联供应商
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initSupplierId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setLinkedText(SUPPLIER_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化关联供应商联系人
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initSupplierContact(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.SUPPLIER_CONTACT.getCode());
        fieldAttrEntity.setLinkedText(SUPPLIER_CONTACT_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(true);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("relied");
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }


    /**
     * 初始化关联采购合同
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initPurchaseId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.PURCHASE.getCode());
//        fieldAttrEntity.setLinkedText(PURCHASE_NAME_LINK_TEXT.anEnum.getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化供应商跟进业务
     *
     * @param fieldAttrEntity 字段属性实体
     * @author feng.zheng
     * @date 2019/2/1 10:27
     */
    public static void initCommunicateBusiness(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(XbbRefTypeEnum.PURCHASE.getName());
        Integer purchaseCode = XbbRefTypeEnum.PURCHASE.getCode();
        itemPoJo.setValue(purchaseCode.toString());
        itemPoJo.setChecked(true);
        itemPoJos.add(itemPoJo);
        fieldAttrEntity.setItems(itemPoJos);
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("relied");
        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.SUPPLIER.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    /**
     * 初始化位置字段
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initAddress(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLocationCenterFlag(0);
        fieldAttrEntity.setLocationCenter(new ArrayList<>());
        TuningPoJo tuningPoJo = new TuningPoJo();
        tuningPoJo.setEnable(1);
        tuningPoJo.setRadius(1000);
        fieldAttrEntity.setTuning(tuningPoJo);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initMemo(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(AT_USERNAME.anEnum.getAttr());
        fieldAttrEntity.setDefaultName(SupplierCommunicateEnum.MEMO.getAttrName());
    }
}
